# 第一阶段：使用 Node 镜像构建
FROM node:18 as builder

# 接收构建参数
ARG BUILD_ENV=production
ENV BUILD_ENV=$BUILD_ENV

WORKDIR /app
COPY package*.json ./
RUN npm config set registry https://registry.npmmirror.com/
RUN npm install
COPY . .

# 根据环境参数执行不同的构建命令
RUN if [ "$BUILD_ENV" = "uam" ]; then \
        npm run build:uam; \
    else \
        npm run build; \
    fi

# 第二阶段：使用 Nginx 镜像
FROM nginx
LABEL maintainer="vueadmin"
COPY --from=builder /app/dist /usr/share/nginx/html  
COPY vueadmin.nginx.conf /etc/nginx/nginx.conf
RUN chown nginx:nginx -R /usr/share/nginx/html
EXPOSE 80